﻿using System;
using System.Windows.Input;
using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.ViewModel;

namespace FamilyBook.UI.WPF.ViewModels
{
    public class BaseDetailsViewModel<TModel> : NotificationObject, IViewModel
    {
        protected BaseDetailsViewModel(TModel model)
        {
            this.Model = model;
            this.Result = ViewModelResult.None;
            this.ConfirmCommand = new DelegateCommand(DoConfirm);
            this.CancelCommand = new DelegateCommand(DoCancel);
        }

        #region IViewModel
        public event EventHandler ViewCompleted;
        public ViewModelResult Result { get; set; }
        #endregion

        public TModel Model { get; private set; }
        
        public ICommand ConfirmCommand { get; private set; }
        public ICommand CancelCommand { get; private set; }

        protected virtual void DoConfirm()
        {
            this.Result = ViewModelResult.Confirm;
            if (ViewCompleted != null)
                ViewCompleted(this, EventArgs.Empty);
        }
        protected virtual void DoCancel()
        {
            this.Result = ViewModelResult.Cancel;
            if (ViewCompleted != null)
                ViewCompleted(this, EventArgs.Empty);
        }
    }

    public enum ViewModelResult
    {
        None = 0,
        Confirm = 1,
        Cancel = 2
    }
}
